package com.example.showlocation;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

public class AddLocation_BDActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_location_bdactivity);
    }
    class MyLocationListener extends BDAbstractLocationListener {
        @Override
        public void onReceiveLocation(BDLocation bdLocation) {
            String addr = bdLocation.getAddrStr();    //获取详细地址信息
            Log.d(getLocalClassName()+":", addr);
        }
    }
    @SuppressLint("IntentReset")
    public void AddLocation_BD(View view) throws Exception {
        MyLocationListener myListener = new MyLocationListener();
        LocationClient mLocationClient =new LocationClient(getApplicationContext()) ;
        mLocationClient.registerLocationListener(myListener);
        LocationClientOption option = new LocationClientOption();
        option.setIsNeedAddress(true);
        option.setNeedNewVersionRgc(true);
        mLocationClient.setLocOption(option);

        LocationClient.setKey("f0mIjDLut8moW8HKsOt3EPXKUwzneEUH");
        LocationClient.setAgreePrivacy(true);
        mLocationClient.start();
    }
}